﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HotDealD2.Models.ModelView;

namespace HotDealD2.Models.ModelManager
{
    public class CartModel
    {
        private List<CartView> listCartView = new List<CartView>();

        public void AddItem(Deal deal, int quantity)
        {
            CartView cartview = listCartView.Where(p => p.deal.MaDeal == deal.MaDeal).FirstOrDefault();
            if (cartview == null)
            {
                listCartView.Add(new CartView { deal = deal, quantity = quantity, PriceItem = decimal.ToInt32(deal.GiaTien) });
            }
            else
            {
                cartview.quantity += quantity;
                cartview.PriceItem = decimal.ToInt32(deal.GiaTien) * cartview.quantity;
            }
        }
        public void RemoveLine(Deal deal)
        {
            listCartView.RemoveAll(l => l.deal.MaDeal == deal.MaDeal);
        }
        public int CaculatorPrice()
        {
            int Price =0;
            for(int i =0;i<listCartView.Count;i++)
            {
               Price += listCartView[i].PriceItem;
            }
            return Price;
        }
        public IList<CartView> CartView
        {
            get {return listCartView;}
        }
    }
}